﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Common.Extensions;

namespace Chinaer.Dao.EF
{
    public class CustomerCaoZuoDAO : Repository<Model.Entities.Model_Customer_CaoZuo>, Chinaer.IDao.ICustomer_CaoZuoDAO
    {
        public override bool Add(Model.Entities.Model_Customer_CaoZuo entity)
        {
            return base.Add(entity);
        }
        public override bool Delete(Model.Entities.Model_Customer_CaoZuo entity)
        {
            entity.IsModelBaseNullThrowException();
            entity.IsUse = false;
            entity.IsDelete = true;
            return base.Update(entity);
        }
        public override bool Delete(string id)
        {
            Model.Entities.Model_Customer_CaoZuo model_CustomerCaoZuo = GetByID(id);
            return Delete(model_CustomerCaoZuo);
        }
        public override int DeleteByIDs(IList<string> listID)
        {
            using (ChinaerContext context = ChinaerContext.GetNewInstance())
            {
                var queryResult = from s in context.CustomerCaoZuos
                                  where listID.Contains(s.ID)
                                  select s;
                foreach (var item in queryResult)
                {
                    context.Entry<Model.Entities.Model_Customer_CaoZuo>(item).State = System.Data.Entity.EntityState.Modified;
                    item.IsUse = false;
                    item.IsDelete = true;
                }
                return context.SaveChanges();
            }
        }
        public override bool Exists(string id)
        {
            return GetByID(id) == null ? false : true;
        }
        public override Model.Entities.Model_Customer_CaoZuo GetByID(string id)
        {
            using (ChinaerContext context = ChinaerContext.GetNewInstance())
            {
                return context.CustomerCaoZuos.Where(s => s.IsUse == true && s.IsDelete == false && s.ID.Equals(id, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
            }
        }
        public override IList<Model.Entities.Model_Customer_CaoZuo> Query(string sql, int pageIndex, out int recordCount, int pageSize, params System.Data.SqlClient.SqlParameter[] sqlParams)
        {
            return base.Query(sql, pageIndex, out recordCount, pageSize, sqlParams);
        }
        public override bool Update(Model.Entities.Model_Customer_CaoZuo entity)
        {
            return base.Update(entity);
        }
    }
}
